<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('标签打印预览')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <div th:object="${assetDetail}" style="margin-top: 50px;">
        <input type="hidden" th:value="*{id}" id="id">
        <h4 class="text-center" th:text="*{companyName}" style="margin-bottom: 20px"></h4>
        <div class="col-sm-4 col-sm-offset-3">
            <label>资产名称：</label>
            <span th:text="*{assetName}" id="assetName"></span><br>
            <label>规格型号：</label>
            <span th:text="*{specifications}" id="specifications"></span>/<span th:text="*{assetModel}" id="assetModel"></span><br>
            <label>资产编码：</label>
            <span th:text="*{assetCode}" id="assetCode"></span><br>
            <label>资产情况：</label>
            <span th:text="*{useStatus}"></span><br>
            <label>使  用  人：</label>
            <span th:text="*{useUser}" id="useUser"></span><br>
            <label>使用部门：</label>
            <span th:text="*{useDeptName}" id="useDeptName"></span>/<span th:text="${company}"></span><br>
            <label>管理部门：</label>
            <span th:text="*{manageDeptName}" id="manageDeptName"></span>/<span th:text="${company}"></span><br>
            <label>位        置：</label>
            <span th:text="*{address}" id="address"></span><br>
            <label>数        量：</label>
            <span th:text="*{amount}" id="amount"></span>
        </div>
        <div id="qrcode" style="margin-top: 40px">
        </div>
        <object id="LODOP_OB" classid="clsid:2105C259-1E0C-4534-8141-A753534CB4CA" width=0 height=0>
            <embed id="LODOP_EM" type="application/x-print-lodop" width=0 height=0 pluginspage="install_lodop64.exe"></embed>
        </object>
        <div style="margin-top: 120px;text-align: center">
            <input type="button" class="btn btn-success" value="打印" name="B3"  onclick="prn_No()">
            <!--<input type="button" class="btn btn-success" value="指定打印" name="B3"  onclick="prn_No()">-->
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: datetimepicker-js" />
<script type="text/javascript" th:src="@{/js/qrcode.js}"></script>
<script th:src="@{/js/LodopFuncs.js}"></script>
<script type="text/javascript">
    var qrcode = new QRCode("qrcode",{height:100,width:100});
    var id=$("#id").val();
    var qrCodeUrl = '[[${qrCodeUrl}]]';
    var idStr = '[[${assetDetail.assetNo}]]';
    var useDate = '[[${assetDetail.useDate}]]';
    var amount= '[[${assetDetail.amount}]]';
    qrcode.makeCode(qrCodeUrl+"/inventory/inventory/mobileInventory/"+id);
    var LODOP; //声明为全局变量
    function prn_No() {
        layer.prompt({
            formType: 2,
            placeholder: '输入开始值',
            title: '请输入值',
        }, function(value, index, elem){
            var reg = /^[1-9]\d*$/;
            if($.common.isEmpty(value)||!reg.test(value)||parseInt(value)>parseInt($("#amount").text())){
                layer.tips("请输入正确的编号",$('.layui-layer-input'));
                return;
            }
            if($('#zxr').val()===""){
                layer.tips("请输入结束值",$('#zxr'));
                return;
            }
            if(!reg.test($('#zxr').val())||parseInt($('#zxr').val())>parseInt($("#amount").text())||parseInt($('#zxr').val())<parseInt(value)){
                layer.tips(parseInt($('#zxr').val())<parseInt(value)?"结束值不小于开始值":"请输入正确的编号",$('#zxr'));
                return;
            }
            LODOP = getLodop($("#LODOP_OB"), $("#LODOP_EM"));
                LODOP.PRINT_INIT("打印标签");
                for(var i=value;i<=parseInt($('#zxr').val());i++){
                    create(i);
                }
                LODOP.PREVIEW();
            layer.close(index);
        });
        $(".layui-layer-content").append("<br/><input type='text' id= 'zxr' class='layui-layer-input' placeholder='输入结束值'/>");
    }
    function create(i) {

        LODOP.ADD_PRINT_BARCODE("8mm", "14mm", "30mm", "25mm", "QRCode", qrCodeUrl+"/inventory/inventory/mobileInventory/"+id+","+i);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 10);
        LODOP.ADD_PRINT_TEXT("70mm", "3mm", "90mm", "", "株洲高科物业管理有限公司");
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "10mm", "90mm", "", "卡片编号:"+idStr);
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "14mm", "90mm", "", "资产编码:"+$("#assetCode").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "18mm", "90mm", "", "资产名称:"+$("#assetName").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "22mm", "90mm", "", "使用人:"+$("#useUser").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "26mm", "90mm", "", "使用部门:"+$("#useDeptName").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "30mm", "90mm", "", "管理部门:"+$("#manageDeptName").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        if (useDate != null) {
            var date = new Date(useDate);
            useDate=date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate();
        }
        LODOP.ADD_PRINT_TEXT("88mm", "34mm", "90mm", "", "开始使用时间:"+useDate);
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "38mm", "90mm", "", "规格型号:"+$("#specifications").text()+"/"+$("#assetModel").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "42mm", "90mm", "", "数量:"+amount+"-"+i);
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);

        LODOP.SET_PRINT_STYLE("Bold", 1);
        LODOP.SET_PRINT_STYLE("FontSize", 8);
        LODOP.ADD_PRINT_TEXT("88mm", "46mm", "90mm", "", "存放地点:"+$("#address").text());
        LODOP.SET_PRINT_STYLEA(0,"Angle",90);
        LODOP.NEWPAGE();
    }
    function submitHandler() {
        $.modal.close(layer.index);
    }
</script>
</body>
</html>